home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 8 / Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO / 047a / lex_yacc.arj / DIGRAM.L < prev    next >
Text File  |  1989-05-28  |  901b  |  27 lines

  1.  
  2.   { This is a sample Lex program that produces a digram table of
  3.     the input file (counts all pairs of lowercase letters). The input
  4.     file normally is standard input (console); use input redirection
  5.     to print the digram for a file.
  6.     This program shows the use of REJECT to reprocess matched patterns
  7.     when patterns to be detected may overlap or include each other.
  8.     This is a Turbo Pascal Lex version of a UNIX Lex program discussed
  9.     in the (SUN) UNIX Lex manual, section 7.4. }
  10.  
  11.   uses LexLib;
  12.   var digram : array ['a'..'z','a'..'z'] of integer;
  13. %%
  14. [a-z][a-z]    begin inc(digram[yytext[1],yytext[2]]); reject end;
  15. .        |
  16. \n        ;
  17. %%
  18. var c,d : char;
  19. begin
  20.   for c := 'a' to 'z' do for d := 'a' to 'z' do
  21.     digram[c,d] := 0;
  22.   if yylex=0 then
  23.     for c := 'a' to 'z' do for d := 'a' to 'z' do
  24.       if digram[c,d]<>0 then
  25.     writeln(c,d,': ',digram[c,d])
  26. end.
  27.